package com.leve.admin.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.CompoundIndex;
import org.springframework.data.mongodb.core.index.CompoundIndexes;
import org.springframework.data.mongodb.core.mapping.Document;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Size;
import java.util.Date;
import java.util.List;
import java.util.Set;

@ApiModel("此刻")
@Data
@Document
@CompoundIndexes({
        @CompoundIndex(def = "{'location': '2dsphere', 'access': 1}"),
        @CompoundIndex(def = "{'user.id': 1, 'access': 1, 'created_date': -1}"),
        @CompoundIndex(def = "{'zones.id': 1, 'created_date': -1}", sparse = true)
})
public class Post {
    @ApiModelProperty(value = "标识", readOnly = true)
    @Null
    private String id;

    @ApiModelProperty(position = 1, value = "图片或者视频地址", required = true, allowableValues = "range[1,256]")
    @NotBlank
    @Size(min = 1, max = 256)
    private String picture;

    @ApiModelProperty(position = 2, value = "图片或者视频高度", required = true)
    @NotNull
    private Integer pictureHeight;

    @ApiModelProperty(position = 3, value = "图片或者视频宽度", required = true)
    @NotNull
    private Integer pictureWidth;

    @ApiModelProperty(position = 4, value = "缩略图地址", required = true, allowableValues = "range[1,256]")
    @NotBlank
    @Size(min = 1, max = 256)
    private String smallPicture;

    @ApiModelProperty(position = 5, value = "描述", allowableValues = "range[0,200]")
    @Size(max = 200)
    private String text;

    @ApiModelProperty(position = 6, value = "经纬度", required = true, example = "[113.943549,22.548181]")
    @NotNull
    @Size(min = 2, max = 2)
    private List<Double> location;

/*    @ApiModelProperty(position = 8, value = "关联空间:0-9个", required = true)
    @Valid
    @Size(max = 9)
    private List<PostZone> zones;*/

    @ApiModelProperty(position = 9, value = "点赞总数", readOnly = true)
    private Integer totalVoters;

    @ApiModelProperty(position = 10, value = "点赞用户标识")
    @JsonIgnore
    private Set<String> voterIds;

    @ApiModelProperty(position = 11, value = "评论总数", readOnly = true)
    private Integer totalComments;

    @ApiModelProperty(position = 12, value = "评论", readOnly = true)
    private List<EmbeddedComment> comments;

    @ApiModelProperty(position = 13, value = "创建者", required = true)
    @NotNull
    private User user;

    @ApiModelProperty(position = 14, value = "创建人", readOnly = true)
    @CreatedDate
    private String createdBy;

    @ApiModelProperty(position = 14, value = "创建日期时间", readOnly = true)
    @CreatedDate
    private Date created_date;

    @ApiModelProperty(position = 15, value = "最后修改者", readOnly = true)
    @Size(max = 64)
    private String lastModifiedBy;

    @ApiModelProperty(position = 16, value = "最后修改日期时间", readOnly = true)
    @LastModifiedDate
    private Date lastModifiedDate;
    @ApiModelProperty(position = 17, value = "查询者是否点过赞", readOnly = true)
    @Transient
    private Boolean voted;

    @ApiModelProperty(position = 18, value = "话题标识", readOnly = true)
    @Null
    private String threadId;

    @ApiModelProperty(position = 19, value = "话题名称", allowableValues = "range[0,20]")
    @Size(max = 20)
    private String threadName;

    @ApiModelProperty(position = 20, value = "是否迁移", readOnly = true)
    private Boolean flag;

}
